<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script src="${ctxStatic}/jquery/jquery-1.9.1.min.js"></script>
<script src="${ctxStatic}/jquery/keyboard.js"></script>
<html>
<head>
<%@ include file="/WEB-INF/views/include/head.jsp"%>
<link rel="stylesheet" href="${ctxStatic}/css/list_erp.css">
<link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
<link rel="stylesheet" href="${ctxStatic}/css/keyboard_style.css">
<style>
	table {
		/* margin-top: 40px; */
		margin-left: -10px;
		border-collapse: separate;
		border-spacing: 0;
		border: 2px #000;
		text-align: center;
        /* margin: 0 auto; */
	}
	table thead tr,table tbody tr {
		height: 50px;
		line-height: 50px;
	}
	table tr th:first-child,table tr td:first-child {/*设置table左边边框*/
		border-left: 2px solid #eaeaea;
	}
	table tr th:last-child,table tr td:last-child {/*设置table右边边框*/
		border-right: 2px solid #eaeaea;
	}
	table tr td:first-child,
	table tr td:nth-child(2),
	table tr td:nth-child(3),
	table tr td:last-child{/*设置table表格每列底部边框*/
		border-bottom: 2px solid #eaeaea;
	}
	table tr th {
		background: #eaeaea;
	}
	table tr:first-child th:first-child {
		border-top-left-radius: 0px;
	}

	table tr:first-child th:last-child {
		border-top-right-radius: 0px;
	}
	table tr:last-child td:first-child {
		border-bottom-left-radius: 0px;
	}

	table tr:last-child td:last-child {
		border-bottom-right-radius: 0px;
	}
	
	.selectedColor{
		background:#595959;
	}
	.unSelectedColor{
		background:#DDDDDD;
	}
</style>
<script type="text/javascript">
	$(document).ready(function(){
		$(".broken").css("background","#ADADAD");
	});
	/* 断料保存  */
	function updateStatus(styleId,materialId) {
		/*如果面料总单耗为0*/
		if ($("#materialUnitExpend").val() == "0") {
			/* 面料总单耗为0，不能断料！ */
			alert("<spring:message code='broken_material_alert_cannotBreak'/>");
			return;
		}
		var url = "${ctx}/updateStatus";
		unFormat($("#write"));
		params = {
			"styleId":styleId,
			"materialQuantity":$("#write").val(),
			"materialId":materialId
		}
		$.post(url,params,function(result){
			if (result == "true") {
				tipParent('<spring:message code='broken_material_Success'/>');
				window.parent.searchContact('${makeFlag}');
				closeWin();
            } else {
            	tipParent('<spring:message code='broken_material_Failed'/>');
            }
		});
	}
	
	/* 选择 待断料订单    */
	function selectOrder(flag,obj){
		if (flag == 0) {
			obj.style.background = "#595959";
			$(obj).attr("onclick","selectOrder(1,this)");
			$(obj).text("已选中");
			$("#styleIdList").val($("#styleIdList").val()+$(obj).val()+"-");
		}else if (flag == 1) {
			obj.style.background = "#DDDDDD";
			$(obj).attr("onclick","selectOrder(0,this)");
			$(obj).text("选择");
			$("#selAllBtn").attr("onclick","selectAll(0,this)");
			$("#selAllBtn").text("全选");
			$("#styleIdList").val($("#styleIdList").val().replace($(obj).val()+"-" , ""));
		}
	}
	
	/* 全选     */
	function selectAll(flag,obj){
		if (flag == 0) {
			$(obj).attr("onclick","selectAll(1,this)");
			$(obj).text("取消全选");
			$(".selectButton").css("background","#595959");
			$(".selectButton").attr("onclick","selectOrder(1,this)");
			$(".selectButton").text("已选中");
			$(".selectButton").each(function(i,e){
				$("#styleIdList").val($("#styleIdList").val()+$(e).val()+"-");
			})
		}else if (flag == 1) {
			$(obj).attr("onclick","selectAll(0,this)");
			$(obj).text("全选");
			$(".selectButton").css("background","#DDDDDD");
			$(".selectButton").attr("onclick","selectOrder(0,this)");
			$(".selectButton").text("选择");
			$("#styleIdList").val("");
		}
	}
	/*  */
	function confirmSelect(){
		if ($("#styleIdList").val() == "") {
			tipParent("请选择订单");
			return;
		}
		window.parent.frames[0].$("#saveBrokenBtn").val($("#styleIdList").val());
		closeWin();
	}
</script>
</head>
<body>
<div>
<input type="hidden" id="styleIdList" value="${styleIdList }"/>
<c:set value="-${styleIdList }" var="styleIdListTemp"/>
<div style="width:100%;padding-left:20px;padding-bottom:10px;box-sizing:border-box;" class="topBtnClose">
	<span style="font-size:37px;margin-top:20px;display:inline-block;"><spring:message code='title_broken_material'/></span>
	<div class="" style="width:45%;position: relative;float: right;margin-top: 3%;">
		<button style="width:150px;height: 50px;font-size: 32px;border:none;border-radius:5px;margin-bottom:10px;background:#595959;color:#ffffff;"  type="button" value="${materialAll.styleIdList}" onclick="confirmSelect()"><spring:message code='button_ok'/></button>
		&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;
		<button style="width:150px;height: 50px;font-size: 32px;border:none;border-radius:5px;margin-bottom:10px;background:#595959;color:#ffffff;"  type="button" value="${materialAll.styleIdList}" onclick="closeWin()"><spring:message code='button_cancel'/></button>
	</div>
</div>
<hr>
<div class="smOrderBox" style="height: 84%;width: 100%;float: left;overflow: auto;">
	<table style=" border:0px" cellspacing="0">
		<tr>
			<!-- 订单号 -->
			<th style="width:42%;font-size: 32px;">订单号</th>
			<!-- 单耗 -->
			<th style="width:33%;font-size: 32px;">单耗</th>
			<!-- 操作-->
			<th style="width:350px;font-size: 32px;">
				<button id="selAllBtn" style="width:100%;height: 50px;font-size: 32px;border:none;border-radius:5px;margin:5px 0;background:#595959;color:#ffffff;" type="button" onclick="selectAll(1,this);"
					value="${orderTemp.styleMaterialEntity.styleId}">取消全选</button>
			</th>
		</tr>
	</table>
	<table style=" border:0px;" cellspacing="0" >
		<c:forEach items="${materialOrderList}"  var="orderTemp" varStatus="status">
			<tr style="background-color:#f1f3f2;">
				<td style="width:42%;text-align:center;font-size: 32px;border-bottom: 1px solid #000;">
					<p>${orderTemp.orderEntity.orderNo}</p>
				</td>
				<td style="width:33%;text-align:center;font-size: 32px;border-bottom: 1px solid #000;">
					<p>${orderTemp.styleMaterialEntity.materialUnitExpend}</p>
				</td>
				<td style="width:350px;text-align:center;font-size: 32px;border-bottom: 1px solid #000;">
					<button style="width:100%;height: 50px;font-size: 32px;border:none;border-radius:5px;margin:5px 0;color:#ffffff;" type="button"
						value="${orderTemp.styleMaterialEntity.styleId}"
						<c:choose>
							<c:when test="${orderTemp.styleOperatingEntity.operatingStatus eq 'OPERATING_STATUS-OS_00' && (fn:indexOf(styleIdListTemp, fn:replace('-,-', ',', orderTemp.styleMaterialEntity.styleId))) != -1}">
								class="selectButton selectedColor"
								onclick="selectOrder(1,this);">已选中
							</c:when>
							<c:when test="${orderTemp.styleOperatingEntity.operatingStatus eq 'OPERATING_STATUS-OS_00' && (fn:indexOf(styleIdListTemp, fn:replace('-,-', ',', orderTemp.styleMaterialEntity.styleId))) == -1}">
								class="selectButton unSelectedColor"
								onclick="selectOrder(0,this);">选择
							</c:when>
							<c:otherwise>
								class="broken">已断
							</c:otherwise>
						</c:choose></button>
						
				</td>
			</tr>
		</c:forEach>
	</table>
</div>
</div>
</body>
</html>